#include "nodeStack.h"
int pushStack(node_t** head, node_t** tail, char* pathname){ // pathname = /home/joey/netdisk_-one-two/12_NetDisk/server
    node_t* pNew = (node_t*)malloc(sizeof(node_t));
    pNew->pathname = "/";
    pNew->Next = NULL;
    pNew->Prev = NULL;
    if(*head == NULL){
        *head = pNew;
        *tail = pNew;
    }
    char* p = strtok(pathname, "/");
    node_t* pNew2 = (node_t*)malloc(sizeof(node_t));
    pNew2->pathname = p;
    pNew2->Next = NULL;
    pNew2->Prev = NULL;
    (*tail)->Next = pNew2;
    *tail = pNew2;
    while((*head != NULL) && ((p = strtok(NULL, "/")) != NULL)){
        node_t* New = (node_t*)malloc(sizeof(node_t));
        New->pathname = p;
        New->Next = NULL;
        New->Prev = NULL;
        (*tail)->Next = New;
        New->Prev = *tail;
        *tail = New;
    }
    return 0;
}
int push(node_t** head, node_t** tail, char* pathname){
    node_t* pNew = (node_t*)malloc(sizeof(node_t));
    char* p = strtok(pathname, "/");
    pNew->pathname = p;
    pNew->Next = NULL;
    pNew->Prev = NULL;
    (*tail)->Next = pNew;
    pNew->Prev = *tail;
    *tail = pNew;
    while((p = strtok(NULL, "/")) != NULL){
        node_t* New = (node_t*)malloc(sizeof(node_t));
        New->pathname = p;
        New->Next = NULL;
        New->Prev = NULL;
        (*tail)->Next = New;
        New->Prev = *tail;
        *tail = New;
    }
    return 0;
}
int pop(node_t** head, node_t** tail){
    node_t* pCur = *tail;
    if(strcmp(pCur->pathname,"server") == 0){
        return 0;
    }
    *tail = (*tail)->Prev;
    (*tail)->Next = NULL;
    free(pCur);
}